<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="预警项">
          <!-- <el-input v-model="dataForm.eventCode" placeholder="预警项" clearable></el-input> -->
          <el-select v-model="dataForm.eventCode" placeholder="请选择..." filterable clearable>
            <el-option v-for="(item,index) in eventList" :key="index" :label="item.eventName" :value="item.eventCode">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="业务单号">
          <el-input v-model="dataForm.refCode" placeholder="业务单号" clearable></el-input>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :custom="{immediate:true}">
        <template v-slot:buttons>
          <!-- <el-button v-if="$hasPermission('msg:msgBizContent:save')" type="primary" @click="addOrUpdateHandle()">{{
          $t('add') }}</el-button> -->
          <el-button v-if="$hasPermission('msg:msgBizContent:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <el-dropdown trigger="click" style="padding-left: 5px;" placement="bottom">
            <el-button icon="el-icon-download" circle>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-bottom" @click.native="exportHandle(true)">导出当前页</el-dropdown-item>
              <el-dropdown-item icon="el-icon-download" @click.native="exportHandle()">全部导出
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <!--  锁定表头设置   :height="this.tableHeight" -->
        <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize :sort-config="{trigger:'cell'}"
          @sort-change="sortChange" @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
          :data="dataList">
          <vxe-table-column type="checkbox" align="center" width="60" :visible="$hasPermission('msg:msgBizContent:delete')"></vxe-table-column>
          <vxe-table-column field="id" title="ID" min-width="120" align="center" :visible="false"> </vxe-table-column>
          <vxe-table-column field="eventCode" title="预警项" min-width="100">
            <template slot-scope="scope">
              {{$getDataItem(eventList,scope.row.eventCode,'eventCode').eventName}}
            </template>
          </vxe-table-column>
          <vxe-table-column field="remark" title="业务内容" min-width="120" align="left" header-align="center"></vxe-table-column>
          <vxe-table-column field="refCode" title="业务单号" min-width="100" align="center"> </vxe-table-column>
          <vxe-table-column field="bizSort" title="业务类别" min-width="100" :visible="false">
            <template slot-scope="scope">
              {{$getDictLabel('MSG_BIZ_SORT', scope.row.bizSort)}}
            </template>
          </vxe-table-column>
          <vxe-table-column field="bizType" title="业务类型" min-width="100" :visible="false">
            <template slot-scope="scope">
              {{$getDictLabel('MSG_BIZ_TYPE1', scope.row.bizType)}}
            </template>
          </vxe-table-column>
          <vxe-table-column field="timePoint" title="临界点" width="140" align="center"></vxe-table-column>
          <vxe-table-column field="pushType" title="预警消息" width="100" align="center">
            <template slot-scope="scope">
              {{$getDictLabel('MSG_PUSH_TYPE', scope.row.pushType)}}
            </template>
          </vxe-table-column>
          <vxe-table-column field="content" title="用户参数" width="140" align="center" :visible="false">
          </vxe-table-column>
          <vxe-table-column field="updateDate" title="最后更新时间" width="140" align="center">
          </vxe-table-column>
          <vxe-table-column title="handle" width="70" show-overflow="false" fixed="right" align="center">
            <template slot-scope="scope">
              <!-- <el-button v-if="$hasPermission('msg:msgBizContent:update')" type="text" size="small" icon="el-icon-edit"
                @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button> -->
              <el-button v-if="$hasPermission('msg:msgBizContent:delete')" type="text" size="small" icon="el-icon-delete"
                @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
            </template>
          </vxe-table-column>
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="pageSizes" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      </div>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './msgBizContent-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/msg/msgBizContent/page',
        getDataListIsPage: true,
        deleteURL: '/msg/msgBizContent',
        deleteIsBatch: true,
        exportURL: '/msg/msgBizContent/export'
      },
      headLock: false,
      eventList: [],
      dataForm: {
        eventCode: '',
        timePoint: '',
        refCode: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
    this.loadEventList()
  },
  methods: {
    loadEventList () {
      this.$http.get('/msg/msgBizEvent/list', { params: { flag: 1 } }).then(({ data: res }) => {
        this.eventList = res.data
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
